home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_091 / adlrun / adlmacro.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  110 lines

  1. #include <stdio.h>
  2.  
  3. #include "adltypes.h"
  4. #include "adlprog.h"
  5. #include "adlrun.h"
  6.  
  7. struct    macro
  8.     *mactab;
  9.  
  10. extern char
  11.     *calloc();
  12.  
  13. define( str1, str2 )
  14. char
  15.     *str1,
  16.     *str2;
  17. {
  18.     struct macro
  19.     *temp;
  20.  
  21.     temp = (struct macro *)calloc( sizeof( struct macro ), 1 );
  22.     if( temp == (struct macro *)0 )
  23.     error( 27 );            /* Out of memory */
  24.  
  25.     temp->next = mactab;
  26.     mactab = temp;
  27.     strcpy( mactab->name, str1 );
  28.     strcpy( mactab->val, str2 );
  29. }
  30.  
  31.  
  32. int16
  33. nummacro()
  34. {
  35.     int16
  36.     count;
  37.     struct macro
  38.     *m;
  39.  
  40.     count = 0;
  41.     for( m = mactab; m; m = m->next )
  42.     count++;
  43.     return count;
  44. }
  45.  
  46.  
  47. undef( str )
  48. char
  49.     *str;
  50. {
  51.     struct macro
  52.     *which,
  53.     *last;
  54.  
  55.     if( !mactab )        /* No macros defined */
  56.     return;
  57.     if( !strcmp( mactab->name, str ) ) {    /* First entry is the one we want */
  58.     which = mactab;
  59.     mactab = mactab->next;
  60.     free( mactab );
  61.     return;
  62.     }
  63.     which = mactab->next;
  64.     last = mactab;
  65.     while( which ) {
  66.     if( !strcmp( which->name, str ) ) {
  67.         last->next = which->next;
  68.         free( which );
  69.         return;
  70.     }
  71.     last = which;
  72.     which = which->next;
  73.     }
  74. }
  75.  
  76.  
  77. char    *
  78. expand( str )
  79. char
  80.     *str;
  81. {
  82.   struct macro
  83.     *which;
  84.  
  85.     which = mactab;
  86.     while( which ) {
  87.     if( !strcmp( which->name, str ) )
  88.         return which->val;
  89.     which = which->next;
  90.     }
  91.     return str;
  92. }
  93.  
  94.  
  95. clearmacro()
  96. {
  97.     struct macro
  98.     *which, *temp;
  99.  
  100.     which = mactab;
  101.     while( which ) {
  102.     temp = which->next;
  103.     free( which );
  104.     which = temp;
  105.     }
  106.     mactab = (struct macro *)0;
  107. }
  108.  
  109. /*** EOF adlmacro.c ***/
  110.